import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-07-12
 * Time: 0:00
 */
class Solution2 {
    public int halveArray(int[] nums) {
        PriorityQueue<Double> heap = new PriorityQueue<>((a, b)-> b.compareTo(a));

        double sum = 0.0;

        for(int x : nums) {
            heap.offer((double)x);
            sum += x;
        }

        sum /= 2.0;

        int count = 0;

        while(sum > 0) {
            double t = heap.poll() / 2.0;
            count++;
            sum -= t;
            heap.offer(t);
        }
        return count;
    }
}
